<?php require_once('../../core/import.php');?>
<?php User::Permission('INTERVIEW_UPDATE'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        #图片处理
        $Result=Upload::Probe($_FILES['ThumbnailPath'],Config::UPLOAD_ATTACHMENT_SIZE_IMAGE,Config::UPLOAD_ATTACHMENT_EXT_IMAGE,Config::PATH_UPLOAD_ATTACHMENT_TEMP);
        
        #如果重新上传了图片，处理
        $FileName=NULL;
        if($Result['error']!=UPLOAD_ERR_NO_FILE)    //如果上传了文件
        {
            switch($Result['error'])
            {
                case UPLOAD_ERR_OK:
                    $FileName=Upload::Execute($_FILES['ThumbnailPath'],Config::PATH_UPLOAD_ATTACHMENT_TEMP);
                break;
                case Upload::UPLOAD_ERR_CUSTOM_EXT:
                    exit('{"Number":"2","Description":"缩略图格式不正确，只能是：'.join(',',Upload::$UPLOAD_EXT_IMAGE).'。"}');
                break;
                case Upload::UPLOAD_ERR_CUSTOM_SIZE:
                    exit('{"Number":"3","Description":"缩略图大小超过了限制，不能超过：'.Functions::SizeFormat(Config::UPLOAD_ATTACHMENT_SIZE_IMAGE).'。"}');
                break;
                default :
                    exit('{"Number":"4","Description":"缩略图上传失败。错误代码：'.$Result['error'].'，错误描述：'.$Result['message'].'。"}');
            }
        }
		
		#数据处理
		$OldData=DB::GetRowByIDForFields('interview',Functions::FormArgs('ID'),'M_IsCurrent,M_IsTop');
		$Data=array
		(
		 	'Name'=>Functions::FormArgs('Name'),
		 	'Guest'=>Functions::FormArgs('Guest'),
			'Title'=>Functions::FormArgs('Title'),
			'Content'=>Functions::FormArgs('Content',NULL,FALSE),
			'Summary'=>Functions::FormArgs('Summary')
		);
		
		if($FileName){
			$Data['ThumbnailPath']=$FileName;
		}
		
		if($_POST['M_IsCurrent']!=$OldData['M_IsCurrent']){
			$Data['M_IsCurrent']=$_POST['M_IsCurrent'];
		}	
		
		if($_POST['M_IsTop']!=$OldData['M_IsTop']) 
		{
			$Data['M_IsTop']=$_POST['M_IsTop'];
			$Data['M_IsTop_Datetime']=date('Y-m-d G:i:s');
		}

        DB::UpdateRowByID('interview',Functions::FormArgs('ID'),$Data);
        echo '{"Number":"0","Description":"成功执行"}';
    }
?>